#include <iostream>
#include "ThreadPool.h"

void exampleTask(int n) {
    std::this_thread::sleep_for(std::chrono::milliseconds(100 * n));
    std::cout << "Task " << n << " completed by thread "
              << std::this_thread::get_id() << std::endl;
}

int main() {
    ThreadPool pool(4); // 创建包含 4 个线程的线程池

//    std::vector<std::future<void>> results;

//    for (int i = 1; i <= 8; ++i) {
//        results.emplace_back(pool.submit(exampleTask, i));
//    }

//    for (auto& result : results) {
//        result.get(); // 等待所有任务完成
//    }


    for (int i = 1; i <= 8; ++i) {
                pool.enqueue(exampleTask, i);
            }

    std::cout << "All tasks completed." << std::endl;
    return 0;
}
